# -*- coding: utf-8 -*-

'''eof
name:申请人与工商信息法定代表人一致性校验
code:R06_EG_BusinessInformationCorporationCheck
tableName:
columnName:
groups:企业业务信息校验
dependencies:EG_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''


import sys
import pandas as pd
import json
from datetime import datetime
reload(sys)
sys.setdefaultencoding('utf-8')


def FormatData(tableName):
    try:
        eg = EG_DSJ.get("data").get("R1103V3")[0].get(tableName)
        return eg if isinstance(eg, list) else [{}]
    except:
        return [{}]


def getRule06():
    null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']
    try:
        basic_list = FormatData("basicList")
        legalPerson = ratingRequest.get("legalPerson")
        if basic_list == [{}]:
            raise RuntimeError("未能获取到工商信息")
        else:
            if len(basic_list) >= 1:
                for i in basic_list:
                    frName = i.get("frName")
                    if frName not in null_type_list and frName == legalPerson:
                        return 1
                    elif frName not in null_type_list:
                        return 0
                    else:
                        raise ValueError("工商信息中法人姓名为空frName = " + frName)
            else:
                raise RuntimeError("工商信息为空")
    except:
        raise


if __name__ == "__main__":
    ratingRequest = {"legalPerson":u"马云峰","bb":""}
    file_obj = open(r'../data/rating/R06_EG_BusinessInformationCorporationCheck/EG_DSJ.json', 'r')
    content = file_obj.read()
    EG_DSJ = json.loads(content, strict=False)
    aa = getRule06()
    print aa

result = getRule06()

